/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;

/**
 *
 * @author Administrator
 */
@Entity
@Table(name = "provider")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Provider.findAll", query = "SELECT p FROM Provider p"),
    @NamedQuery(name = "Provider.findByProviderId", query = "SELECT p FROM Provider p WHERE p.providerId = :providerId"),
    @NamedQuery(name = "Provider.findByName", query = "SELECT p FROM Provider p WHERE p.name = :name"),
    @NamedQuery(name = "Provider.findByInitials", query = "SELECT p FROM Provider p WHERE p.initials = :initials"),
    @NamedQuery(name = "Provider.findBySocialReason", query = "SELECT p FROM Provider p WHERE p.socialReason = :socialReason"),
    @NamedQuery(name = "Provider.findByNit", query = "SELECT p FROM Provider p WHERE p.nit = :nit"),
    @NamedQuery(name = "Provider.findByAddress", query = "SELECT p FROM Provider p WHERE p.address = :address"),
    @NamedQuery(name = "Provider.findByEmail", query = "SELECT p FROM Provider p WHERE p.email = :email"),
    @NamedQuery(name = "Provider.findByEmail2", query = "SELECT p FROM Provider p WHERE p.email2 = :email2"),
    @NamedQuery(name = "Provider.findByPhone", query = "SELECT p FROM Provider p WHERE p.phone = :phone"),
    @NamedQuery(name = "Provider.findByPhone2", query = "SELECT p FROM Provider p WHERE p.phone2 = :phone2"),
    @NamedQuery(name = "Provider.findByFax", query = "SELECT p FROM Provider p WHERE p.fax = :fax"),
    @NamedQuery(name = "Provider.findByWebsite", query = "SELECT p FROM Provider p WHERE p.website = :website"),
    @NamedQuery(name = "Provider.findByMainImage", query = "SELECT p FROM Provider p WHERE p.mainImage = :mainImage"),
    @NamedQuery(name = "Provider.findByLogo", query = "SELECT p FROM Provider p WHERE p.logo = :logo"),
    @NamedQuery(name = "Provider.findByReportLogo", query = "SELECT p FROM Provider p WHERE p.reportLogo = :reportLogo"),
    @NamedQuery(name = "Provider.findByDateCreation", query = "SELECT p FROM Provider p WHERE p.dateCreation = :dateCreation"),
    @NamedQuery(name = "Provider.findByClient", query = "SELECT p FROM Provider p WHERE p.client = :client"),
    @NamedQuery(name = "Provider.findByUserId2", query = "SELECT p FROM Provider p WHERE p.userId2 = :userId2"),
    @NamedQuery(name = "Provider.findByProviderIdMax", query = "SELECT max(p.providerId) FROM Provider p"),
    @NamedQuery(name = "Provider.findByActive", query = "SELECT p FROM Provider p WHERE p.active = :active order by p.name")})
public class Provider implements Serializable {
    private static final long serialVersionUID = 1L;
    /*
    @Id
    @Basic(optional = false)
    @Column(name = "providerId")*/
    @Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer providerId;
    
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    
    @Column(name = "initials")
    private String initials;
    
    @Column(name = "socialReason")
    private String socialReason;
    
    @Column(name = "nit")
    private String nit;
    
    @Column(name = "address")
    private String address;
    
    @Column(name = "email")
    private String email;
    
    @Column(name = "email2")
    private String email2;
    
    @Column(name = "phone")
    private String phone;
    
    @Column(name = "phone2")
    private String phone2;
    
    @Column(name = "fax")
    private String fax;
    
    @Column(name = "website")
    private String website;
    
    @Column(name = "mainImage")
    private String mainImage;
    
    @Column(name = "logo")
    private String logo;
    
    @Column(name = "reportLogo")
    private String reportLogo;
    
    @Column(name = "dateCreation")
    @DateTimeFormat(pattern = "dd/MM/yyyy")
    private Date dateCreation;
    
    @Basic(optional = false)
    @Column(name = "client")
    private boolean client;
    
    @Column(name = "userId2")
    private Integer userId2;
    
    @Column(name = "active")
    private Boolean active;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "provider")
    private Collection<Userprovider> userproviderCollection;
    
    @JoinColumns({
        @JoinColumn(name = "regionId", referencedColumnName = "regionId"),
        @JoinColumn(name = "localityId", referencedColumnName = "localityId")})
    @ManyToOne
    private Locality locality;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "provider")
    private Collection<Product> productCollection;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "providerId")
    private Collection<Accountspayable> accountspayableCollection;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "provider")
    private Collection<Providerpharmacy> providerpharmacyCollection;

    public Provider() {
    }

    public Provider(Integer providerId) {
        this.providerId = providerId;
    }

    public Provider(Integer providerId, String name, boolean client) {
        this.providerId = providerId;
        this.name = name;
        this.client = client;
    }
    
    

    public Integer getProviderId() {
        return providerId;
    }

    public void setProviderId(Integer providerId) {
        this.providerId = providerId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getInitials() {
        return initials;
    }

    public void setInitials(String initials) {
        this.initials = initials;
    }

    public String getSocialReason() {
        return socialReason;
    }

    public void setSocialReason(String socialReason) {
        this.socialReason = socialReason;
    }

    public String getNit() {
        return nit;
    }

    public void setNit(String nit) {
        this.nit = nit;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getEmail2() {
        return email2;
    }

    public void setEmail2(String email2) {
        this.email2 = email2;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPhone2() {
        return phone2;
    }

    public void setPhone2(String phone2) {
        this.phone2 = phone2;
    }

    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    public String getWebsite() {
        return website;
    }

    public void setWebsite(String website) {
        this.website = website;
    }

    public String getMainImage() {
        return mainImage;
    }

    public void setMainImage(String mainImage) {
        this.mainImage = mainImage;
    }

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public String getReportLogo() {
        return reportLogo;
    }

    public void setReportLogo(String reportLogo) {
        this.reportLogo = reportLogo;
    }

    public Date getDateCreation() {
        return dateCreation;
    }

    public void setDateCreation(Date dateCreation) {
        this.dateCreation = dateCreation;
    }

    public boolean getClient() {
        return client;
    }

    public void setClient(boolean client) {
        this.client = client;
    }

    public Integer getUserId2() {
        return userId2;
    }

    public void setUserId2(Integer userId2) {
        this.userId2 = userId2;
    }

    public Boolean getActive() {
        return active;
    }

    public void setActive(Boolean active) {
        this.active = active;
    }

    @XmlTransient
    public Collection<Userprovider> getUserproviderCollection() {
        return userproviderCollection;
    }

    public void setUserproviderCollection(Collection<Userprovider> userproviderCollection) {
        this.userproviderCollection = userproviderCollection;
    }

    public Locality getLocality() {
        return locality;
    }

    public void setLocality(Locality locality) {
        this.locality = locality;
    }

    @XmlTransient
    public Collection<Product> getProductCollection() {
        return productCollection;
    }

    public void setProductCollection(Collection<Product> productCollection) {
        this.productCollection = productCollection;
    }

    @XmlTransient
    public Collection<Accountspayable> getAccountspayableCollection() {
        return accountspayableCollection;
    }

    public void setAccountspayableCollection(Collection<Accountspayable> accountspayableCollection) {
        this.accountspayableCollection = accountspayableCollection;
    }

    @XmlTransient
    public Collection<Providerpharmacy> getProviderpharmacyCollection() {
        return providerpharmacyCollection;
    }

    public void setProviderpharmacyCollection(Collection<Providerpharmacy> providerpharmacyCollection) {
        this.providerpharmacyCollection = providerpharmacyCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (providerId != null ? providerId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Provider)) {
            return false;
        }
        Provider other = (Provider) object;
        if ((this.providerId == null && other.providerId != null) || (this.providerId != null && !this.providerId.equals(other.providerId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Provider[ providerId=" + providerId + " ]";
    }
    
}
